package com.minimoment.model.service.impl;

import com.minimoment.base.BaseSupportImpl;
import com.minimoment.model.domain.UMcomemt;
import com.minimoment.model.service.UMcomentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by etund on 2014/11/1.
 */
@Service
@Transactional
public class UMcomentServiceImpl extends BaseSupportImpl<UMcomemt> implements UMcomentService {
    private List<UMcomemt> umComemts = new ArrayList<UMcomemt>();
//    寻找票评论数最多的6条影评
    @Override
    public List<UMcomemt> findBest(int i) {
        umComemts =  getSession().createQuery("from UMcomemt").list();
        return umComemts;
    }

    @Override
    public List<UMcomemt> getHot(Long l1, Long l2, Integer i) {
        if(l2>l1){
            Long t;
            t = l1;
            l1 = l2;
            l2 = t;
        }
        if(i!=null) {
            umComemts = getSession().createQuery("from UMcomemt um where (um.movie.flag>=?) and (um.movie.flag<=?) order by um.littles.size desc ")
                    .setParameter(0, l1).setParameter(1, l2).setMaxResults(i).list();
        }else {
            umComemts = getSession().createQuery("from UMcomemt um where (um.movie.flag>=?) and (um.movie.flag<=?) order by um.littles.size desc ")
                    .setParameter(0, l1).setParameter(1, l2).list();
        }
        return umComemts;
    }
}
